home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form Form1
- BorderStyle = 3 'Fixed Dialog
- Caption = "Define areas in a PictureBox and know if the user clicked there"
- ClientHeight = 4800
- ClientLeft = 45
- ClientTop = 330
- ClientWidth = 5400
- MaxButton = 0 'False
- MinButton = 0 'False
- ScaleHeight = 4800
- ScaleWidth = 5400
- ShowInTaskbar = 0 'False
- StartUpPosition = 3 'Windows Default
- Begin VB.CommandButton Command2
- Caption = "Hide areas"
- Height = 345
- Left = 2730
- TabIndex = 2
- Top = 3990
- Width = 1485
- End
- Begin VB.CommandButton Command1
- Caption = "Show areas"
- Height = 345
- Left = 1155
- TabIndex = 1
- Top = 3990
- Width = 1485
- End
- Begin VB.PictureBox Pic
- AutoRedraw = -1 'True
- Height = 2850
- Left = 210
- ScaleHeight = 2790
- ScaleWidth = 4995
- TabIndex = 0
- Top = 1050
- Width = 5055
- End
- Begin VB.Label Label3
- AutoSize = -1 'True
- Caption = "Source code written by Damian Janowski - jano@sinectis.com"
- BeginProperty Font
- Name = "Tahoma"
- Size = 8.25
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 195
- Left = 105
- TabIndex = 5
- Top = 4515
- Width = 5205
- End
- Begin VB.Label Label2
- Alignment = 2 'Center
- Caption = "Click on the PictureBox and see what happens..."
- Height = 225
- Left = 210
- TabIndex = 4
- Top = 630
- Width = 5055
- End
- Begin VB.Label Label1
- Alignment = 2 'Center
- Caption = "Define areas in a PictureBox and know if the user clicked there"
- BeginProperty Font
- Name = "Arial"
- Size = 8.25
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 510
- Left = 210
- TabIndex = 3
- Top = 105
- Width = 5085
- End
- Attribute VB_Name = "Form1"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- Private Type AREA
- Left As Integer
- Top As Integer
- Width As Integer
- Height As Integer
- End Type
- Const NUM_AREAS = 2 'the number of areas you want to use
- ' - 1, because the zero is included
- Dim Ar(NUM_AREAS) As AREA
- Dim CurArea As Integer
- Function DefineArea(AreaNumber As Integer, iLeft As Integer, iTop As Integer, iWidth As Integer, iHeight As Integer)
- 'Don't forget that the zero IS included!
- With Ar(AreaNumber)
- .Left = iLeft
- .Top = iTop
- .Width = iWidth
- .Height = iHeight
- End With
- End Function
- Function UserClickedArea(X As Integer, Y As Integer) As Boolean
- Dim I As Integer
- For I = 0 To NUM_AREAS
- With Ar(I)
- If X >= .Left And X <= .Left + .Width And _
- Y >= .Top And Y <= .Top + .Height Then
- UserClickedArea = True
- CurArea = I
- Exit For
- Else
- CurArea = -1
- End If
- End With
- Next
- End Function
- Private Sub Command1_Click()
- DrawAreas Pic
- End Sub
- Private Sub Command2_Click()
- Pic.Cls
- End Sub
- Private Sub Form_Load()
- ' This will define 3 areas
- Dim I As Integer
- For I = 0 To NUM_AREAS
- With Ar(I)
- .Left = I * (Pic.ScaleWidth / 3)
- .Top = I * (Pic.ScaleHeight / 3)
- .Width = Pic.ScaleWidth / 3
- .Height = Pic.ScaleHeight / 3
- End With
- Next
- End Sub
- Private Sub Pic_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
- ' The function sets CurArea to the area number
- ' clicked
- ' Else, CurArea = -1
- If UserClickedArea(CInt(X), CInt(Y)) Then MsgBox "You clicked the area number " & CurArea
- End Sub
- Function DrawAreas(C As Control)
- Dim I As Integer
- For I = 0 To NUM_AREAS
- With Ar(I)
- C.Line (.Left, .Top)-(.Left, .Top + .Height)
- C.Line (.Left, .Top)-(.Left + .Width, .Top)
- C.Line (.Left + .Width, .Top)-(.Left + .Width, .Top + .Height)
- C.Line (.Left, .Top + .Height)-(.Left + .Width, .Top + .Height)
- End With
- Next
- End Function
-